<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<style>
.cot0,.cot1,.cot2,.cot3,.cot4,.cot5 {
	width: 140px;
	float: left;
	vertical-align: middle;
	display: inline-block;
	display: table-cell;
}

.cot0 {
	width: 30px;
}

.cot1 {
	width: 170px;
}
</style>
<script type="text/javascript" language="JavaScript">
	function CloseMySelf(sender) {
		var radios = document.getElementsByName("radioselect");
		var formValid = false;
		var i = 0;
		while (!formValid && i < radios.length) {
			if (radios[i].checked)
				formValid = true;
			i++;
		}
		if (!formValid) {
			alert("Must check some option!");
			return formValid;
		} else
			var x, y, z, n;
		var town, county, country, postcode, addressid;
		try {
			var radios = document.getElementsByName("radioselect");

			var i = 0;
			while (i < radios.length) {
				if (radios[i].checked) {
					x = radios[i].value.trim();
					y = "postcode" + x;
					z = "town" + x;
					n = "county" + x;
					postcode = document.getElementById(y).value;
					town = document.getElementById(z).value;
					county = document.getElementById(z).value;					
					addressid = x;
				}
				i++;
			}
		} catch (err) {
		}
		window.opener.document.getElementById("postcode").value = postcode;
		window.opener.document.getElementById("townid").value = town;
		window.opener.document.getElementById("countyid").value = county;		
		window.opener.document.getElementById("addressid").value = addressid;
		window.close();
		return true;
	}
	function closeWindow() {
		window.open('', '_self', '');
		window.close();
	}
</script>
<div style="display: block; float: right; clear: both;width: 780px">
	<h2 style="color: green; font-weight: bold">Search PostCode</h2>
	<form action="searchaddress" method="POST">
		<div>
			Postcode: <input type="text" name="postcode" style="margin: 5px">
			Street: <input type="text" name="street" style="margin: 5px">
			Town: <input type="text" name="town" style="margin: 5px">
		</div>

		<div
			style="float: left; clear: both; display: block; width: 100%; padding-top: 15px">
			<input class="button_css" type="submit" value="Search Address">
			<input class="button_css" type="submit" value="None"> <input
				class="button_css" type="reset" value="Clear"> <br /> <br>

		</div>
	</form>
	<ul>
		<li class="li_title">
			<div class="cot0">-</div>
			<div class="cot1">Address</div>
			<div class="cot2">Post code</div>
			<div class="cot3">Town</div>
			<div class="cot4">County</div>
			<div class="cot5">Country</div> <c:if test="${!empty addressList}">
		</li>
		<form method="post" onsubmit="checkRadio()">
			<c:forEach items="${addressList}" var="address">
				<li><div class="cot0" style="padding: 5px 2px">
						<input type="radio" name="radioselect" value="${address.id}" /> <input
							type="hidden" name="radioselect" id="address${address.id}"
							value="${address.id}" /> <input type="hidden" name="radioselect"
							id="town${address.id}" value="${address.town.id}" /> <input
							type="hidden" name="radioselect" id="postcode${address.id}"
							value="${address.getPostcode()}" />
					</div>
					<div class="cot1">${address.address1}</div>
					<div class="cot2">${address.postcode}</div>
					<div class="cot2">${address.town.townName}</div>
					<div class="cot3">${address.town.county.countyName}</div>
					<div class="cot4">${address.town.county.country.countryName}</div>
				</li>
			</c:forEach>
			</c:if>
			<div
				style="width: 100%; float: left; cleat: both; display: block; margin-top: 15px;">
				<div style="float: left;">
					<input type="submit" id="btSelect" value="Select"
						class="button_css" onclick="return CloseMySelf(this);"> <a
						href="" onclick="closeWindow();"><input class="button_css"
						type="submit" id="btClose" value="Close"> </a>
				</div>
				<div class="phantrang">
					Pre
					<c:if test="${!empty prepage}">
						<a href="?page=${prepage}">${prepage}</a>
					</c:if>
					Page <input style="width: 35px;" class="curpage" type="text"
						name="b" value="${curpage}" /> of <span class="nops">1</span> <a
						href="?page=${nextpage}">${nextpage}</a> <a href="">Next </a>
				</div>
		</form>
	</ul>
</div>